<template>
    <div class="login">
        <div class="register" @click="change"><img :src="captchaBlob"></div>
  <van-form @submit="onSubmit">
  <van-field
    v-model="name"
    name="用户名"
    placeholder="请输入用户名"
    :rules="[{ required: true }]"
    autocomplete
  />
  <van-field
    v-model="mobile"
    name="手机号"
    placeholder="请输入手机号"
    :rules="[{ required: true }]"
    autocomplete
  />
  <van-field
    v-model="password"
    type="password"
    placeholder="请输入密码"
    :rules="[{ required: true }]"
    autocomplete
  />
  <van-field
    v-model="checkCode"
    type="checkCode"
    placeholder="请输入验证码"
    :rules="[{ required: true }]"
    autocomplete
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit">注册</van-button>
  </div>
</van-form>
    </div>
</template>
<script>
import Vue from 'vue';
import { Toast } from 'vant';
Vue.use(Toast);
import {checkCodeQuery,registerQuery,checkCodeCheck} from "../service/index"
export default {
  data() {
    return {
      name: '',
      mobile:'',
      password: '',
      checkCode:'',
      captchaBlob: null,
      captchaDataUrl: ''
    };
  },
  methods: {
    async onSubmit() {
      console.log('submit', this.name,this.password,this.checkCode.toLocaleLowerCase());
      let res=await checkCodeCheck({checkCode:this.checkCode.toLocaleLowerCase()});
      if(!res.status==200){
        Toast(res.data.errorInfo);
      }else{
        let res1=await registerQuery({name:this.name,mobile:this.mobile,password:this.password,state:2});
        if(res1.data.code==200){
          Toast("注册成功");
          this.$router.push("/pending")
        }
        if(res1.data.code==500){
          Toast(res1.data.message);
        }
      }
      


    },
    async checkCodes(){
        let res=await checkCodeQuery();
        this.captchaBlob=res.data;
        this.captchaBlob= URL.createObjectURL(this.captchaBlob);
    },
    change(){
     this.checkCodes()
    }
  },
  created (){
    this.checkCodes()
  }
};
</script>
<style scoped lang="scss">
.login{
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    .register{
        position: absolute;
        left: 20px;
        top: 300px;
        z-index: 100;
        color: rgb(81, 190, 226);
        font-weight: 700;

    }
    .van-form{
    margin-top: 50px;
    width: 90%;
    :deep(.van-field__control){
        margin: -7px;
    }
    .van-cell{
        border: 1px solid gray;
        height: 30px;
        margin: 0 20px;
        margin-bottom: 20px;
    }
}
.van-button--round {
    border-radius: 5px;
    position: absolute;
    bottom: 40px;
    width: 92%;
}
}

</style>
